// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';
import store from './store/';
import components from '@/components/index';
Vue.config.productionTip = false;

Object.keys(components).forEach((key) => {
  var name = key.replace(/(\w)/, (v) => v.toUpperCase()) //首字母大写
  Vue.component(`v${name}`, components[key])
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
});

var docEl = document.documentElement
var transefromRemHandle = function (preWidth) {
  var fontEl = document.createElement('style')
  var base = 100
  return function () {
    // debugger
    var clientWidth = window.document.documentElement.clientWidth
    var rem = clientWidth / preWidth * base
    console.log(rem)
    console.log(clientWidth)
    docEl.setAttribute('data-rem', rem)
    fontEl.innerHTML = 'html{font-size:' + rem + 'px!important;}'
    docEl.firstElementChild.appendChild(fontEl)
  }
}

if (document.documentElement.clientWidth > 768) {
  transefromRemHandle(1920)()
} else {
  transefromRemHandle(750)()
}
var windowResize = window.onresize

window.onresize = function () {
  windowResize()

  if (document.documentElement.clientWidth > 768) {
    transefromRemHandle(1920)()
  } else {
    transefromRemHandle(750)()
  }
  // transefromRem()
}
